<?php

/**
 * 店铺
 * @copyright (c) 2013, Mr.Wang
 * @author Mr.Wang <281762391@qq.com>
 */
class ShopAction extends HomeAction {

    public function _initialize() {
        parent::_initialize();
        $area_id = format_int(cookie('area_id'));
        if ($area_id == 0) {
            $this->error("对不起,请您先选择地区");
        }
        G::$Cache['area_id'] = $area_id;
    }

    function _filter(&$map) {
        $keywords = $_GET['keyword'];
        if (!empty($keywords)) {
            //$map['shop_name'] = array("like", "%" . $keywords . "%");
            $map['_string']   = '(shop_name like "%' . $keywords . '%")  OR ( shop_tag like "%' . $keywords . '%") ';
        }
        $map['shop_area'] = array("like", "%" . G::$Cache['area_id'] . "%");
    }

    function _before_index() {
        $_REQUEST ['listRows'] = 8;
        $this->seo("店铺列表");
    }

    function view() {
        $name  = $this->getActionName();
        $model = M($name);
        $id    = $_REQUEST [$model->getPk()];
        if (!$id) {
            $id = $_REQUEST ['id'];
        }
        $vo = $model->find($id);
        if ($vo) {
            cookie("shop_id", $vo['shop_id']);
        }
        $this->seo($vo['shop_name']);
        $this->assign('vo', $vo);
        $this->display();
    }

}
